$(function() {
	//toolbar权限控制
	toolBarPermission()
	var editor;
	$.operate.get(api + '/admin/route', function(res) {
		var json = res.data;
		try {
			for (var i = 0; i < json.length; i++) {
				var route = json[i];
				if (route.predicates) {
					var predicates = route.predicates;
					route.predicates = JSON.parse(predicates);
				}
				if (route.filters) {
					var filters = route.filters;
					route.filters = JSON.parse(filters);
				}
			}
			editor = new JsonEditor('#json-display', json, {
				defaultCollapsed: false, //默认展开所有
			});
		} catch (ex) {
			console.log('Wrong=', ex);
		}
	}, false)
	//更新
	$('#jsonData').on('click', function() {
		var newjson = editor.get();
		$.ajax({
			url: api + "/admin/route",
			type: 'put',
			headers: {
				'content-type': 'application/json;charset=UTF-8'
			},
			data: JSON.stringify(newjson),
			success: function(res) {
				if (res.code == 0) {
					// $.operate.successCallback(res);
					$.modal.msgSuccess( '更新操作成功');
				} else {
					$.modal.alertError(res.msg);
				}
			}
		})
	});
});
